/**
 * 
 */
package jmine.tec.aom.domain.impl;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

import jmine.tec.aom.AOMMessages;
import jmine.tec.aom.domain.AbstractPropertyValue;
import jmine.tec.aom.exception.FillException;
import jmine.tec.persist.annotation.DiscriminatorComment;
import bancosys.tec.component.Documentation;

/**
 * {@link AbstractPropertyValue} implementation for the {@link BigDecimal} type.
 * 
 * @author jrenaut
 */
@Entity
@DiscriminatorValue("11")
@DiscriminatorComment("BIG DECIMAL")
public class BigDecimalPropertyValue extends AbstractPropertyValue<BigDecimal> {

    /**
     * {@inheritDoc}
     */
    @Override
    @Column(name = "VL_BIG_DECIMAL", precision = 29, scale = 16)
    @Documentation("VALOR DA CARACTERISTICA DO TIPO BIG DECIMAL")
    public BigDecimal getValue() {
        return super.getValue();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void doSetValue(String stringValue) throws FillException {
        try {
            this.setValue(new BigDecimal(stringValue));
        } catch (NumberFormatException e) {
            throw new FillException(AOMMessages.INVALID_NUMBER_FORMAT.create(this.getPropertyName(), stringValue), e);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String doGetValueAsString() {
        return this.getValue().toPlainString();
    }
}
